package aom.ju.ss.view.user.shop.management

import android.content.Intent
import android.view.View
import androidx.core.content.ContextCompat
import aom.ju.ss.R
import aom.ju.ss.databinding.LayoutOrderAddress2Binding
import aom.ju.ss.lpInterface.BindViewInterface
import aom.ju.ss.lpInterface.TitleDialogInterface
import aom.ju.ss.mode.ReceivingAddressData
import aom.ju.ss.mode.ReceivingAddressList
import aom.ju.ss.utils.VG
import aom.ju.ss.utils.http.LP_API
import aom.ju.ss.utils.show
import aom.ju.ss.utils.start
import aom.ju.ss.utils.startResult
import aom.ju.ss.view.base.BaseListActivity
import aom.ju.ss.view.dialog.TitleDialog
import com.google.gson.Gson

/**
 * 退货地址列表
 */
class ReturnAddressList : BaseListActivity() {

    override fun api(): String {
        return LP_API.shop_refund_address_address_list
    }

    override fun interFace(): BindViewInterface {

        return BindViewInterface { b, position ->
            val bin = b as LayoutOrderAddress2Binding
            val info = getLists()[position] as ReceivingAddressData
            bin.info = info
            bin.layAddress.setOnClickListener {
                startResult(AddReturnAddress::class.java, 1993, Gson().toJson(info))// api 404
            }
        }
    }

    override fun ok(jsonString: String, httpTY: String) {
        super.ok(jsonString, httpTY)
        val mode = Gson().fromJson(jsonString, ReceivingAddressList::class.java)
        mode.data.let {
            if (it == null) {
                TitleDialog.showMsg(activity, "暂无退货地址,是否现在添加?", object : TitleDialogInterface {
                    override fun ok(view: View?, IsDetermine: Boolean) {
                        startResult(AddReturnAddress::class.java, 1993, "0")// api 404
                    }
                })
            } else {
                setLists(mode.data!!)
            }
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, datas: Intent?) {
        super.onActivityResult(requestCode, resultCode, datas)
        if (requestCode == 199 && resultCode == RESULT_OK) {
            data
        }
    }


    override fun error(e: String, jsonString: String, httpTY: String) {
        super.error(e, jsonString, httpTY)
        e.show
    }

    override fun item(): Int {
        return R.layout.layout_order_address2
    }

    override fun ListonCreate() {
        binding.title.title.text = "退货地址列表"
        binding.title.backImg.setImageResource(R.drawable.ic_back_black)
    }
}